package com.penghaisoft.microwms.product.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.penghaisoft.microwms.common.Constant;
import com.penghaisoft.microwms.common.base.model.BaseDictionary;
import com.penghaisoft.microwms.common.dto.ConProCondDto;
import com.penghaisoft.microwms.common.dto.ProCountingDto;
import com.penghaisoft.microwms.common.dto.ProStorageDto;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.BaseService;
import com.penghaisoft.microwms.common.wms.model.MesConProRequired;
import com.penghaisoft.microwms.common.wms.model.ProContractChange;
import com.penghaisoft.microwms.common.wms.model.ProStorageSn;
import com.penghaisoft.microwms.common.wms.model.ProStorageSnChkHis;
import com.penghaisoft.microwms.common.wms.model.RawLockLog;
import com.penghaisoft.microwms.common.wms.model.RawStorageSn;
import com.penghaisoft.microwms.product.dao.BaseDictionaryMapper;
import com.penghaisoft.microwms.product.dao.ProContractChangeMapper;
import com.penghaisoft.microwms.product.dao.ProStorageSnChkHisMapper;
import com.penghaisoft.microwms.product.dao.ProStorageSnMapper;
import com.penghaisoft.microwms.product.service.IProStorageSnService;

/**
 * @Description 成品库存明细表 service
 * @author luoteng
 * @date 2018年6月6日 下午2:50:00
 * @version 1.0
 */
@Service("proStorageSnService")
public class ProStorageSnServiceImpl extends BaseService implements
		IProStorageSnService {
	@Resource
	private ProStorageSnMapper proStorageSnMapper;
	
	@Resource
	private ProContractChangeMapper proContractChangeMapper;
	
	@Resource
	private ProStorageSnChkHisMapper proStorageSnChkHisMapper;
	
	@Resource 
	private BaseDictionaryMapper baseDictionaryMapper;

	/**
	 * 新增记录
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp create(ProStorageSn proStorageSn) {
		proStorageSnMapper.create(proStorageSn);
		return success();
	}

	/**
	 * 删除记录（逻辑删除）
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp delete(ProStorageSn proStorageSn) {
		proStorageSnMapper.delete(proStorageSn);
		return success();
	}

	/**
	 * 查询列表
	 * 
	 * @param pager
	 * @param baseResource
	 * @return
	 */
	@Override
	public Pager<ProStorageSn> findListByCondition(int page, int rows,
			ProStorageSn condition) {
		Pager<ProStorageSn> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		condition.preQuery();
		long size = proStorageSnMapper.queryCount(condition);
		List<ProStorageSn> records = new ArrayList<ProStorageSn>();
		if (size > 0) {
			records = proStorageSnMapper.queryList(pager, condition);

			ProStorageSn sumAmount = proStorageSnMapper
					.querySumAmount(condition);
			pager.setOrder("{\"amount\":\"" + sumAmount.getAmount() + "\"}");
		}
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}

	/**
	 * 查询单条
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public ProStorageSn findById(String id) {
		return proStorageSnMapper.queryById(id);
	}

	/**
	 * 修改记录
	 * 
	 * @param baseResource
	 * @return
	 */
	@Override
	public Resp update(ProStorageSn proStorageSn) {
		Resp resp = new Resp();
		resp.setCode(Constant.SUCCESS);
		// 查出信息
		ProStorageSn tmp = new ProStorageSn();
		tmp.setStorageSnId(proStorageSn.getStorageSnId());
		List<ProStorageSn> list = proStorageSnMapper.queryByAny(tmp);
		if (list.size() <= 0) {
			resp.setCode(Constant.FAIL);
			resp.setMsg("查询不到条码");
			return resp;
		}
		proStorageSnMapper.updateContractNoBySelect(proStorageSn);
		// 记录合同号修改日志
		if (list.size() > 0) {
			ProContractChange procontractChange = new ProContractChange();
			procontractChange.setBarcode(list.get(0).getBarcode());
			procontractChange.setAmount(list.get(0).getAmount());
			procontractChange.setUnit(list.get(0).getUnit());
			procontractChange.setContractNoOld(list.get(0).getContractNo());
			procontractChange.setContractNoNew(proStorageSn.getContractNo());
			procontractChange.setModel(list.get(0).getModel());
			procontractChange.setModelDesc(list.get(0).getModelDesc());
			procontractChange.setModelType(list.get(0).getModelType());
			procontractChange.setWlCode(list.get(0).getWlCode());
			procontractChange.setCreateBy(proStorageSn.getLastModifiedBy());
			procontractChange.setGmtCreate(proStorageSn.getGmtModified());
			procontractChange.setActiveFlag("1");
			proContractChangeMapper.create(procontractChange);
		}

		return resp;
	}

	@Override
	public Pager<ProStorageDto> findStorageListByCondition(int page, int rows,
			ProStorageDto condition) {
		Pager<ProStorageDto> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		long size = proStorageSnMapper.queryStorageListCount(condition);
		List<ProStorageDto> records = new ArrayList<ProStorageDto>();
		if (size > 0) {
			records = proStorageSnMapper.queryStorageList(pager, condition);

			ProStorageDto sumObj = proStorageSnMapper
					.querySumAmountOb(condition);

			BigDecimal amount = BigDecimal.ZERO;
			BigDecimal iventAmount = BigDecimal.ZERO;
			BigDecimal availAmount = BigDecimal.ZERO;
			BigDecimal lockAmount = BigDecimal.ZERO;
			if (sumObj != null) {
				amount = sumObj.getAmount() == null ? BigDecimal.ZERO : sumObj
						.getAmount();
				iventAmount = sumObj.getIventAmount() == null ? BigDecimal.ZERO
						: sumObj.getIventAmount();
				availAmount = sumObj.getAvailAmount() == null ? BigDecimal.ZERO
						: sumObj.getAvailAmount();
				lockAmount = sumObj.getLockAmount() == null ? BigDecimal.ZERO
						: sumObj.getLockAmount();
			}
			pager.setOrder("{\"amount\":\"" + amount + "\",\"iventAmount\":\""
					+ iventAmount + "\",\"availAmount\":\"" + availAmount
					+ "\",\"lockAmount\":\"" + lockAmount + "\"}");
		}
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}
	
	@Override
	public Pager<ProStorageDto> findStorageListByConditionHZ(int page, int rows,
			ProStorageDto condition) {
		Pager<ProStorageDto> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		long size = proStorageSnMapper.queryStorageListCountHZ(condition);
		List<ProStorageDto> records = new ArrayList<ProStorageDto>();
		if (size > 0) {
			records = proStorageSnMapper.queryStorageListHZ(pager, condition);

			ProStorageDto sumObj = proStorageSnMapper
					.querySumAmountObHZ(condition);

			BigDecimal amount = BigDecimal.ZERO;
			BigDecimal iventAmount = BigDecimal.ZERO;
			BigDecimal availAmount = BigDecimal.ZERO;
			BigDecimal lockAmount = BigDecimal.ZERO;
			if (sumObj != null) {
				amount = sumObj.getAmount() == null ? BigDecimal.ZERO : sumObj
						.getAmount();
				iventAmount = sumObj.getIventAmount() == null ? BigDecimal.ZERO
						: sumObj.getIventAmount();
				availAmount = sumObj.getAvailAmount() == null ? BigDecimal.ZERO
						: sumObj.getAvailAmount();
				lockAmount = sumObj.getLockAmount() == null ? BigDecimal.ZERO
						: sumObj.getLockAmount();
			}
			pager.setOrder("{\"amount\":\"" + amount + "\",\"iventAmount\":\""
					+ iventAmount + "\",\"availAmount\":\"" + availAmount
					+ "\",\"lockAmount\":\"" + lockAmount + "\"}");
		}
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}

	@Override
	public List<ProStorageSn> queryByAny(ProStorageSn proStorageSn) {

		return proStorageSnMapper.queryByAny(proStorageSn);
	}

	@Override
	public List<ProStorageSn> queryLose(ProCountingDto proCountingDto) {

		return proStorageSnMapper.queryLose(proCountingDto);
	}

	@Override
	public List<ProStorageSn> findProStorageSnByCondition(
			ProStorageSn proStorageSn) {

		return proStorageSnMapper.queryProStorageSnByCondition(proStorageSn);
	}

	/**
	 * @Title: updateProStorageSnStatus
	 * @Description: 冻结解冻条码
	 * @date 2018年5月22日 上午11:24:53
	 */
	@Override
	@Transactional
	public Resp updateProStorageSnStatus(List<ProStorageSn> list,
			RawLockLog rawLockLog) {
		ProStorageSn proStorageSn = new ProStorageSn();
		List<Integer> proStorageSnIdList = new ArrayList<Integer>();
		String currentUserName = rawLockLog.getLockBy();
		Date date = new Date();
		for (ProStorageSn tmp : list) {
			proStorageSnIdList.add(tmp.getStorageSnId());

			// ProStorageSn cond = new ProStorageSn();
			// cond.setStorageSnId(tmp.getStorageSnId());
			// // 根据snid（唯一）查询，实际一条sn数据
			// List<ProStorageSn> proStorageSnlist =
			// proStorageSnMapper.queryProStorageSnByCondition(cond);
			// if (proStorageSnlist.size() > 0) {
			// // 冻结解冻日志记录
			// RawLockLog lockLog = new RawLockLog();
			// lockLog.setBarcode(proStorageSnlist.get(0).getBarcode());
			// lockLog.setModel(proStorageSnlist.get(0).getModel());
			// lockLog.setModelDesc(proStorageSnlist.get(0).getModelDesc());
			// lockLog.setWlCode(proStorageSnlist.get(0).getWlCode());
			// lockLog.setLockReason(tmp.getLockReason());
			// lockLog.setLockBy(currentUserName);
			// lockLog.setLockDate(date);
			// lockLog.setLockType(tmp.getBarcodeStatus());
			// lockLog.setGmtCreate(date);
			// lockLog.setCreateBy(currentUserName);
			// lockLog.setActiveFlag("1");
			// rawLockLogMapper.create(lockLog);
			// }

		}
		// rawStorageSnIdList条码集合（一次更新）
		proStorageSn.setProStorageSnIdList(proStorageSnIdList);
		proStorageSn.setLockReason(list.get(0).getLockReason());
		proStorageSn.setLastModifiedBy(currentUserName);
		proStorageSn.setGmtModified(date);
		String status = list.get(0).getBarcodeStatus();
		proStorageSn.setBarcodeStatus(status);
		// 冻结解冻更新状态
		Integer updateCnt = proStorageSnMapper.updateOpenClose(proStorageSn);
		System.out.println("更改数量：" + updateCnt);
		if (updateCnt.intValue() <= 0) {
			throw new RuntimeException("更改条码失败");
		}
		int modiNum = proStorageSn.getProStorageSnIdList().size();
		if (updateCnt.intValue() != modiNum) {
			throw new RuntimeException("更新条码的数量和修改条码的数量不一致！");
		}
		return success();
	}

	@Override
	public Resp updateProStorageSnWl(ProStorageSn proStorageSn) {
		Integer updateCnt = proStorageSnMapper.updateWlByCode(proStorageSn);
		if (updateCnt.intValue() == 1) {
			return success();
		} else {
			return fail("更改状态失败");
		}
	}

	@Override
	public Resp updateProStorageSn(ProStorageSn proStorageSn) {
		Integer updateCnt = proStorageSnMapper.updateBySelect(proStorageSn);
		if (updateCnt.intValue() == 1) {
			return success();
		} else {
			return fail("更改状态失败");
		}
	}

	@Override
	public Resp updateProStorageSnNew(ProStorageSn proStorageSn, ProStorageSnChkHis proStorageSnChkHis) {
		Integer updateCnt = proStorageSnMapper.updateBySelect(proStorageSn);
		
		proStorageSnChkHisMapper.create(proStorageSnChkHis);
		
		if (updateCnt.intValue() == 1) {
			return success();
		} else {
			return fail("更改状态失败");
		}
	}

	/*
	 * @Title: findProStorageSnCharge
	 * 
	 * @Description: 记账in
	 * 
	 * @author jzh
	 * 
	 * @date 2018年7月30日 下午2:21:41
	 */
	@Override
	public Pager<ProStorageSn> findProStorageSnCharge(int page, int rows,
			ProStorageSn proStorageSn) {
		Pager<ProStorageSn> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		proStorageSn.preQuery();

		List<String> modelTypeList = new ArrayList<String>();
		modelTypeList.add(Constant.MODEL_RRT);
		modelTypeList.add(Constant.MODEL_DUT);
		proStorageSn.setModelTypeList(modelTypeList);

		long size = proStorageSnMapper.queryCountChargeIn(proStorageSn);
		List<ProStorageSn> records = new ArrayList<ProStorageSn>();
		if (size > 0) {
			records = proStorageSnMapper.queryListChargeIn(pager, proStorageSn);

			ProStorageSn sumAmount = proStorageSnMapper
					.querySumAmountIn(proStorageSn);
			pager.setOrder("{\"amount\":\"" + sumAmount.getAmount() + "\"}");
		}
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}

	/*
	 * @Title: findChargeOut
	 * 
	 * @Description: 记账出库
	 * 
	 * @author jzh
	 * 
	 * @date 2018年7月31日 下午4:22:58
	 */
	@Override
	public Pager<ProStorageSn> findChargeOut(int page, int rows,
			ProStorageSn proStorageSn) {
		Pager<ProStorageSn> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		proStorageSn.preQuery();

		List<String> modelTypeList = new ArrayList<String>();
		modelTypeList.add(Constant.MODEL_RRT);
		modelTypeList.add(Constant.MODEL_DUT);
		proStorageSn.setModelTypeList(modelTypeList);

		long size = proStorageSnMapper.queryCountChargeOut(proStorageSn);
		List<ProStorageSn> records = new ArrayList<ProStorageSn>();
		if (size > 0) {
			records = proStorageSnMapper
					.queryListChargeOut(pager, proStorageSn);

			ProStorageSn sumAmount = proStorageSnMapper
					.querySumAmountOut(proStorageSn);
			pager.setOrder("{\"amount\":\"" + sumAmount.getAmount() + "\"}");
		}
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}

	/*
	 * @Title: createChargeOut
	 * 
	 * @Description: 记账出库新增
	 * 
	 * @author jzh
	 * 
	 * @date 2018年8月1日 下午3:09:54
	 */
	@Override
	public Resp createChargeOut(ProStorageSn proStorageSn) {
		Resp resp = new Resp();

		ProStorageDto proStorageDto = new ProStorageDto();
		proStorageDto.setModel(proStorageSn.getModel());
		proStorageDto.setModelType(proStorageSn.getModelType());
		List<ProStorageDto> records = proStorageSnMapper.queryStorageList(null,
				proStorageDto);
		if (records == null || records.isEmpty()) {
			resp.setCode(Constant.FAIL);
			resp.setMsg("该原材料型号没有库存！");
			return resp;
		} else {
			ProStorageDto compare = records.get(0);
			if (proStorageSn.getAmount().negate()
					.compareTo(compare.getAvailAmount()) > 0) {
				resp.setCode(Constant.FAIL);
				resp.setMsg("该原材料型号库存不足！");
				return resp;
			}
			proStorageSnMapper.create(proStorageSn);
		}
		return success();
	}

	/*
	 * @Title: updateChargeOut
	 * 
	 * @Description: 记账出库修改
	 * 
	 * @author jzh
	 * 
	 * @date 2018年8月1日 下午3:10:10
	 */
	@Override
	public Resp updateChargeOut(ProStorageSn proStorageSn) {
		Resp resp = new Resp();

		ProStorageSn tmp = proStorageSnMapper.queryById(proStorageSn
				.getStorageSnId().toString());

		ProStorageDto rawStorageDto = new ProStorageDto();
		rawStorageDto.setModel(proStorageSn.getModel());
		rawStorageDto.setModelType(proStorageSn.getModelType());
		List<ProStorageDto> records = proStorageSnMapper.queryStorageList(null,
				rawStorageDto);
		if (records == null || records.isEmpty()) {
			resp.setCode(Constant.FAIL);
			resp.setMsg("该原材料型号没有库存！");
			return resp;
		} else {
			ProStorageDto compare = records.get(0);
			BigDecimal nowAddAmount = proStorageSn.getAmount().negate()
					.subtract(tmp.getAmount().negate());
			if (nowAddAmount.compareTo(BigDecimal.ZERO) > 0) {
				if (nowAddAmount.compareTo(compare.getAvailAmount()) > 0) {
					resp.setCode(Constant.FAIL);
					resp.setMsg("该原材料型号库存不足！");
					return resp;
				}
			}

			proStorageSnMapper.updateBySelect(proStorageSn);
		}
		return success();
	}

	/*
	 * @Title: batchUpdateProContact
	 * 
	 * @Description: 批量修改成品合同号
	 * 
	 * @author jzh
	 * 
	 * @date 2018年8月23日 上午10:15:48
	 */
	@Override
	@Transactional
	public Resp batchUpdateProContact(ProStorageSn proStorageSn) {
		Resp resp = new Resp();
		resp.setCode(Constant.SUCCESS);
		ProStorageSn tmp = new ProStorageSn();
		tmp.setContractNo(proStorageSn.getContractNoOld());
		tmp.setModel(proStorageSn.getModel());
		tmp.setModelType(proStorageSn.getModelType());
		tmp.setWlCode(proStorageSn.getWlCode());
		// 0可用；1 冻结；2已出库 3 报废
		tmp.setBarcodeStatus("0");
		tmp.setActiveFlag("1");
		List<ProStorageSn> list = proStorageSnMapper.queryByAny(tmp);
		if (list != null && !list.isEmpty()) {
			int modiAmount = proStorageSn.getModiAmount() != null ? proStorageSn
					.getModiAmount().intValue() : 0;
			if (modiAmount > list.size()) {
				resp.setCode(Constant.FAIL);
				resp.setMsg("该合同下可用条码小于" + modiAmount + "个！");
				return resp;
			}
			List<Integer> ids = new ArrayList<Integer>();
			for (int i = 0; i < modiAmount; i++) {
				ids.add(list.get(i).getStorageSnId());
			}

			ProStorageSn upOb = new ProStorageSn();
			upOb.setContractNo(proStorageSn.getContractNo());
			upOb.setProStorageSnIdList(ids);
			Integer upAmount = proStorageSnMapper.updateBySelectIds(upOb);
			if (modiAmount > upAmount) {
				throw new RuntimeException("该合同内本次待修改条码状态发生改变，请再次尝试！");
			}

			// 创建合同修改记录
			Date now = new Date();
			ProContractChange proContractChange = null;

			for (int i = 0; i < modiAmount; i++) {
				proContractChange = new ProContractChange();
				proContractChange.setBarcode(list.get(i).getBarcode());
				proContractChange.setAmount(list.get(i).getAmount());
				proContractChange.setUnit(list.get(i).getUnit());
				proContractChange.setContractNoOld(proStorageSn
						.getContractNoOld());
				proContractChange
						.setContractNoNew(proStorageSn.getContractNo());
				proContractChange.setModel(list.get(i).getModel());
				proContractChange.setModelDesc(list.get(i).getModelDesc());
				proContractChange.setModelType(list.get(i).getModelType());
				proContractChange.setWlCode(list.get(i).getWlCode());
				// controller中的登陆人暂存在LastModifiedBy
				proContractChange.setCreateBy(proStorageSn.getLastModifiedBy());
				proContractChange.setGmtCreate(now);
				proContractChange.setActiveFlag("1");
				proContractChangeMapper.create(proContractChange);
			}
		}
		return resp;

	}

	/*
	 * @Title: findConProRequired
	 * 
	 * @Description: 通过合同号，型号查询销售报表数据
	 * 
	 * @author jzh
	 * 
	 * @date 2018年9月20日 下午5:29:01
	 */
	@Override
	public List<MesConProRequired> findConProRequired(
			ConProCondDto conProCondDto) {
		// TODO Auto-generated method stub
		return proStorageSnMapper.findConProRequired(conProCondDto);
	}

	/*
	 * @Title: findStorageListExp
	 * 
	 * @Description: 成品库存导出
	 * 
	 * @author jzh
	 * 
	 * @date 2018年9月29日 下午3:35:53
	 */
	@Override
	public List<ProStorageDto> findStorageListExp(ProStorageDto proStorageDto) {
		// TODO Auto-generated method stub
		return proStorageSnMapper.queryStorageList(null, proStorageDto);
	}
	
	@Override
	public List<ProStorageDto> findStorageListExpHZ(ProStorageDto proStorageDto) {
		// TODO Auto-generated method stub
		return proStorageSnMapper.queryStorageListHZ(null, proStorageDto);
	}

	/*
	 * @Title: findStorageSnListExp
	 * 
	 * @Description: 成品明细导出
	 * 
	 * @author jzh
	 * 
	 * @date 2018年9月30日 下午3:14:15
	 */
	@Override
	public List<ProStorageSn> findStorageSnListExp(ProStorageSn proStorageSn) {
		// TODO Auto-generated method stub
		return proStorageSnMapper.queryList(null, proStorageSn);
	}

	/*
	 * @Title: findKulingList
	 * 
	 * @Description: 成品库龄超期
	 * 
	 * @author jzh
	 * 
	 * @date 2018年10月10日 下午4:21:04
	 */
	@Override
	public Pager<ProStorageSn> findKulingList(int page, int rows,
			ProStorageSn condition) {
		Pager<ProStorageSn> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		condition.preQuery();
		long size = proStorageSnMapper.queryKulingCount(condition);
		List<ProStorageSn> records = new ArrayList<ProStorageSn>();
		if (size > 0) {
			records = proStorageSnMapper.queryKulingList(pager, condition);
		}
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}
	
	/**  
	 * @Title: findQuantitiyProduct
	 * @Description:   接口-查询成品库存
	 * @author Lengxf  
	 * @date 2019年3月11日    
	 */  
	@Override
	public Pager<ProStorageSn> findQuantitiyProduct(int page, int rows, ProStorageSn condition){
		Pager<ProStorageSn> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		List<ProStorageSn> records = new ArrayList<ProStorageSn>();
		long size = proStorageSnMapper.countQuantitiyProduct(condition);
		if(size > 0){
			records = proStorageSnMapper.findQuantitiyProduct(pager, condition);
		}
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}
	
	/**  
	 * @Title: findQuantitiyProductToSn
	 * @Description:   接口-查询成品库存明细
	 * @author Lengxf  
	 * @date 2019年3月11日    
	 */  
	@Override
	public Pager<ProStorageSn> findQuantitiyProductToSn(int page, int rows, ProStorageSn condition){
		
		List<BaseDictionary> modelTypeList = baseDictionaryMapper.queryDicTypeModelTypePro();
		if(condition.getFinishedProductName() != null && !"".equals(condition.getFinishedProductName())){
			if(modelTypeList != null && modelTypeList.size() > 0){
				for(BaseDictionary tmp : modelTypeList){
					if(condition.getFinishedProductName().equals(tmp.getDicName())){
						condition.setFinishedProductName(tmp.getDicCode());
					}
				}
			}
		}
		
		Pager<ProStorageSn> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		List<ProStorageSn> records = new ArrayList<ProStorageSn>();
		long size = proStorageSnMapper.countQuantitiyProductToSn(condition);
		if(size > 0){
			records = proStorageSnMapper.findQuantitiyProductToSn(pager, condition);
		}
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}
	
	@Override
	public Pager<ProStorageSn> queryStorageChangeList(int page, int rows, ProStorageSn proStorageSn){
		Pager<ProStorageSn> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
		proStorageSn.preQuery();
		long size = proStorageSnMapper.queryStorageChangeCount(proStorageSn);
		List<ProStorageSn> records = new ArrayList<ProStorageSn>();
		if (size > 0) {
			records = proStorageSnMapper.queryStorageChangeList(pager, proStorageSn);
		}
		pager.setRecords(records);
		pager.setTotalCount(size);
		return pager;
	}
	
	/**  
	 * @Title: findQuantitiyProductInTime
	 * @Description:   手机APP展示接口-成品超期、未超期库存
	 * @author Lengxf  
	 * @date 2019年3月18日    
	 */  
	@Override
	public List<ProStorageSn> findQuantitiyProductInTime(ProStorageSn condition){
		return proStorageSnMapper.findQuantitiyProductInTime(condition);
	}
}
